home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / mkfmx.exe / MKFMX.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1992-11-21  |  5.6 KB  |  237 lines

  1. {$A-,B-,D-,F+,G+,I-,L-,N-,R-,S-,V-,W-,X+}
  2. {$M 1024,0}   
  3. library UFmExtD;
  4.  
  5. uses wintypes,winprocs,win31,strings;
  6.  
  7. const
  8.   Aplname='MkFmX';
  9.  
  10.   Menu_Text_Len   = 40;
  11.  
  12.   fmMenu_First    = 1;
  13.   fmMenu_Last   = 99;
  14.  
  15.   fmEvent_Load    = 100;
  16.   fmEvent_Unload    = 101;
  17.   fmEvent_InitMenu  = 102;
  18.   fmEvent_User_Refresh  = 103;
  19.   fmEvent_SelChange = 104;
  20.  
  21.   fmFocus_Dir   = 1;
  22.   fmFocus_Tree    = 2;
  23.   fmFocus_Drives    = 3;
  24.   fmFocus_Search    = 4;
  25.  
  26.   fm_GetFocus   = wm_User + $0200;
  27.   fm_GetDriveInfo   = wm_User + $0201;
  28.   fm_GetSelCount    = wm_User + $0202;
  29.   fm_GetSelCountLFN = wm_User + $0203;  { LFN versions are odd }
  30.   fm_GetFileSel   = wm_User + $0204;
  31.   fm_GetFileSellFN  = wm_User + $0205;  { LFN versions are odd }
  32.   fm_Refresh_Windows  = wm_User + $0206;
  33.   fm_Reload_Extensions  = wm_User + $0207;
  34.  
  35. type
  36.   PFMS_GetFileSel = ^TFMS_GetFileSel;
  37.   TFMS_GetFileSel = record
  38.     wTime: Word;
  39.     wDate: Word;
  40.     dwSize: Longint;
  41.     bAttr: Byte;
  42.     szName: array[0..259] of Char;   { always fully qualified }
  43.   end;
  44.  
  45.   PFMS_GetDriveInfo = ^TFMS_GetDriveInfo;    { for drive }
  46.   TFMS_GetDriveInfo = record
  47.     dwTotalSpace: Longint;
  48.     dwFreeSpace: Longint;
  49.     szPath: array[0..259] of Char;   { current directory }
  50.     szVolume: array[0..13] of Char;    { volume label }
  51.     szShare: array[0..127] of Char;    { if this is a net drive }
  52.   end;
  53.  
  54.   PFMS_Load = ^TFMS_Load;
  55.   TFMS_Load = record
  56.     dwSize: Longint;       { for version checks }
  57.     szMenuName: array[0..Menu_Text_Len - 1] of Char;  { output }
  58.     Menu: HMenu;           { output }
  59.     wMenuDelta: Word;      { input }
  60.   end;
  61.  
  62. Function FmExtensionProc(window:hwnd; wparam:word; Lparam:longint):Longint;
  63. export;
  64. forward;
  65.  
  66. exports
  67.  FmExtensionProc index 1;
  68.  
  69. {***************************** implementation *******************}
  70.  
  71. type Titem=record
  72.             title:array[0..15] of char;
  73.             exec :array[0..63] of char;
  74.             wdir :array[0..63] of char;
  75.             pmode:char;
  76.            end;
  77.  
  78.      titemarray=array[1..99] of titem;
  79.  
  80. var Mymenu:hmenu;
  81.     pitem:^titemarray;
  82.     nitem:integer;
  83.  
  84. Function FmExtensionProc(window:hwnd; wparam:word; Lparam:longint):Longint;
  85.  
  86.  procedure doload;
  87.   var data:array[0..79] of  char;
  88.       i,j:integer;
  89.       p:pchar;
  90.       a:string[9];
  91.  
  92.   function GetPstring(name,data:pchar):boolean;
  93.    begin
  94.     getPstring:=getprivateprofilestring(Aplname,name,'',data,78,'winfile.ini')<>0
  95.    end;
  96.  
  97.   procedure getword(var p:pchar; data:pchar; max:integer);
  98.    var p1:pchar;
  99.    begin
  100.     if p=nil then exit;
  101.     p1:=strscan(p,',');
  102.     if p1<>nil then
  103.      begin
  104.       p1^:=#0;
  105.       inc(p1)
  106.      end;
  107.     strlcopy(data,p,max);
  108.     p:=p1
  109.    end;
  110.  
  111.   begin
  112.    nitem:=0;
  113.    with pfms_load(lparam)^ do
  114.     begin
  115.      dwsize:=sizeof(tfms_load);
  116.      if not getPstring('MenuName',data) then exit;
  117.      strlcopy(szmenuname,data,menu_text_len);
  118.      if not getPstring('programs',data) then exit;
  119.      val(data,nitem,i);
  120.      if nitem=0 then exit;
  121.      Mymenu:=createpopupmenu;
  122.      menu:=mymenu;
  123.     end;
  124.    i:=nitem*sizeof(titem);
  125.    getmem(pitem,i);
  126.    fillchar(pitem^,i,0);
  127.    for i:=1 to nitem do with pitem^[i] do
  128.     begin
  129.      str(i,a);
  130.      if getPstring(strpcopy(@a,a),data) then
  131.       begin
  132.        p:=data;
  133.        getword(p,title,15);
  134.        getword(p,exec,63);
  135.        getword(p,wdir,63);
  136.        if p<>nil then pmode:=upcase(p^) else pmode:='S';
  137.        if title[0]='_' then
  138.         begin
  139.          appendmenu(mymenu,mf_separator,0,nil);
  140.          strcopy(title,@title[1]);
  141.         end;
  142.        appendmenu(mymenu,mf_string,i,title);
  143.       end;
  144.     end;
  145.    FmExtensionProc:=mymenu;
  146.   end;
  147.  
  148.  procedure DoUnload;
  149.   begin
  150.    destroymenu(mymenu);
  151.    freemem(pitem,sizeof(titem)*nitem);
  152.   end;
  153.  
  154.  procedure DoExec(which:integer);
  155.  
  156.   const maxlen=512;
  157.  
  158.   var i,j,n,L:integer;
  159.       psel:pfms_getFilesel;
  160.       CmdLine:pchar;
  161.  
  162.   procedure SpecialCommand(what:pchar);
  163.    begin
  164.     if stricomp(what,'@RELOAD')=0 then
  165.      postmessage(window,fm_reload_extensions,0,0)
  166.     else messagebox(window,what,'Unknown special command',
  167.                     mb_ok or Mb_iconStop);
  168.    end;
  169.  
  170.   begin {doexec}
  171.    new(psel);
  172.    getmem(cmdline,maxlen);
  173.    with pitem^[which],psel^ do
  174.     if exec[0]='@' then specialcommand(exec)
  175.     else
  176.      begin
  177.       if wdir[0]<>#0 then chdir(wdir);
  178.       n:=sendmessage(window,fm_getselcount,0,0);
  179.       if (n=0) or (pmode='N') then winexec(exec,sw_normal)
  180.       else if pmode='M' then
  181.        begin
  182.         strcopy(cmdline,exec);
  183.         L:=strlen(exec);
  184.         for i:=0 to n-1 do
  185.          begin
  186.           sendmessage(window,fm_getfilesel,i,longint(psel));
  187.           j:=strlen(szname)+1;
  188.           if (L+j)<maxlen then
  189.            begin
  190.             strcat(cmdline,' ');
  191.             strcat(cmdline,szname);
  192.             inc(L,j)
  193.            end;
  194.          end;
  195.         winexec(cmdline,sw_normal);
  196.        end
  197.       else for I:=0 to n-1 do
  198.        begin
  199.         sendmessage(window,fm_getfilesel,i,longint(psel));
  200.         strcopy(cmdline,exec);
  201.         strcat(cmdline,' ');
  202.         strcat(cmdline,szname);
  203.         winexec(cmdline,sw_normal);
  204.        end;
  205.      end;
  206.    freemem(cmdline,maxlen);
  207.    dispose(psel);
  208.   end;
  209.  
  210.  begin {fmextensionproc}
  211.   FmExtensionproc:=0;
  212.   case wparam of
  213.    fmevent_Load:DoLoad;
  214.    fmevent_unload:DoUnLoad;
  215.    else if (wparam>0) and (wparam<=nitem) then DoExec(wparam);
  216.   end;
  217.  end;
  218.  
  219. begin
  220. end.
  221.  
  222. format of profile:
  223. [MkFmX]
  224. menuname=Extensions
  225. programs=4
  226. 1=Notepad,notepad.exe
  227. 2=Ms,Ms.exe,,m
  228. 3=_Notebook,NoteBook.exe
  229. 4=_Viewer,Fview.exe
  230.  
  231. _=draw separator
  232.  
  233. internal commands:
  234.  
  235. @reload
  236.  
  237.